package com.example.pinkcat.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.pinkcat.R;
import com.example.pinkcat.activity.VideoActivity;
import com.example.pinkcat.activity.ViewAllMyFollow;
import com.example.pinkcat.activity.api.entity.VideoEntity;
import com.example.pinkcat.api.entity.VideowaibuEntity;
import com.example.pinkcat.fragment.shouye.Fragment_zhuifan;
import com.rishabhharit.roundedimageview.RoundedImageView;
import com.example.pinkcat.api.entity.myCollectStaticMsg;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class Zhuifan_m1_RecyclerViewAdapter extends RecyclerView.Adapter<Zhuifan_m1_RecyclerViewAdapter.ViewHolder> {

    private Context context;


    DisplayMetrics dm;


    List<VideoEntity> videoEntities=new ArrayList<>();

    int count = 0;


    public void setData(List<VideoEntity> videoEntities){
        this.videoEntities = videoEntities;
        notifyDataSetChanged();
    }



    public Zhuifan_m1_RecyclerViewAdapter(Context context){
        this.context = context;

        dm = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    }

    static class ViewHolder extends RecyclerView.ViewHolder{

        public RoundedImageView imageView_big;
        public TextView textViewDescription_big;
        public TextView textViewTitlte_big;

        private View video;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView_big=itemView.findViewById(R.id.lis_manga_img_big);
            textViewTitlte_big=itemView.findViewById(R.id.manga_title_big);

            video = itemView.findViewById(R.id.list_video_big);

        }

    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view;
        view= LayoutInflater.from(context).inflate(R.layout.layout_manga_ys_zf,parent,false);


        return new Zhuifan_m1_RecyclerViewAdapter.ViewHolder(view);

    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
         holder.textViewTitlte_big.setText(String.valueOf(videoEntities.get(position).getVideo_name()));//预设标题
                Glide.with(context).load(Uri.parse(videoEntities.get(position).getVideo_cover())).into(holder.imageView_big);//预设图片



    //页面跳转
       holder.video.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, VideoActivity.class);
                intent.putExtra("v_id",videoEntities.get(position).getVideo_id());
                intent.putExtra("up_id",videoEntities.get(position).getUser_id());
                intent.putExtra("v_link",videoEntities.get(position).getVideo_link());
                intent.putExtra("v_labs",videoEntities.get(position).getVideo_lab());
                context.startActivity(intent);
            }
        });

    }


    @Override
    public int getItemCount() {

        return videoEntities.size() ;
    }



    int dip2px(float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
